package cn.uniquetech.bt;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Test {

	private static final String URL = "jdbc:mysql://139.196.177.17:3306/dw";
	private static final String NAME = "root";
	private static final String PASS = "root1234";
	private static final String DRIVER = "com.mysql.jdbc.Driver";

	private static Connection con = null;
	private PreparedStatement ps = null;

	private static void initDB() {

		try {
			Class.forName(DRIVER);
			con = DriverManager.getConnection(URL, NAME, PASS);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String fileName = "E:\\gitpros\\GenPojoTools\\src\\cn\\uniquetech\\bt\\BLE_RM.txt";

	public static void main(String[] args) {
		//initDB();
		StringBuffer sb = new StringBuffer("");
		String sql = "";
		try {
			FileReader reader = new FileReader(fileName);
			BufferedReader br = new BufferedReader(reader);
			String str = null;
			while ((str = br.readLine()) != null) {
				String[] line = str.split(",");
				System.out.println(line.length);
				String btserial = line[0];
				String xcoord = line[1];
				String ycoord = line[2];
				String zcoord = line[3];
				String caddress = "地址" + btserial;
				sql = getInsertSql(btserial, xcoord, ycoord, zcoord, caddress);
				//System.out.println(str);
			}

			br.close();
			reader.close();
			System.out.println(sb.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private static String getInsertSql1(String btserial, String xcoord, String ycoord, String zcoord, String caddress) {
		String sql = "insert into bluetooth (cbtserial,xcoord,ycoord,zcoord,caddress) values ('" + btserial + "','" + xcoord + "','" + ycoord + "','" + zcoord + "','" + caddress + "');";
		//System.out.println(sql);
		return sql;
	}

	private static String getInsertSql(String btserial, String xcoord, String ycoord, String zcoord, String caddress) {
		String sql = "insert into bluetooth (cbtserial,xcoord,ycoord,zcoord,caddress) values ('" + btserial + "','" + xcoord + "','" + ycoord + "','" + zcoord + "','" + caddress + "');";
		//System.out.println(sql);
		return sql;
	}

}
